package com.atguigu.lease.web.admin.context;

import com.atguigu.lease.model.entity.SystemUser;

/**
 * ClassName: LoginUserContext
 * Description:
 *
 * @Auther lpl
 * @Create 2024/7/7 20:47
 * @Version 1.0
 */
public class LoginUserContext {
    //利用threadlocal实现同一个线程的数据共享
    private static ThreadLocal<SystemUser> threadLocal = new ThreadLocal<>();

    public static void setUser(SystemUser systemUser){
        threadLocal.set(systemUser);

    }

    public static SystemUser getUser(){
        return threadLocal.get();
    }

    //切记使用threadlocal时需要释放资源
    public static void removeUser(){
        threadLocal.remove();
    }
}
